<?php



namespace App\Services\Member\Models;

use App\Services\Company\Models\Company;
use App\Services\Company\Models\CompanyRole;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class UserRole extends Model
{
    use HasFactory;
    protected $table = 'shop_user_role_relation';

    protected $fillable = [
        'user_id', 'company_id', 'role_id','expired_at','updated_at','created_at','is_forever_membership','user_count'
    ];

    protected $appends = [
        'expired_days', 'is_expired'
    ];


    public function getExpiredDaysAttribute()
    {
        return  Carbon::now()->diffInDays($this->expired_at,false);
    }

    public function getIsExpiredAttribute()
    {
        return  Carbon::now()->diffInDays($this->expired_at,false) < 0;
    }
    public $timestamps = false;
    public function shop()
    {
        return $this->belongsTo(Company::class, 'company_id');
    }
    public function role()
    {
        return $this->belongsTo(Role::class, 'role_id');
    }
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }



}
